﻿using System;
using System.Collections.Generic;
using System.Text;
using EnCor.Security;

namespace EnCor
{
    public class AuthenticationProviderCollection :IEnumerable<IAuthenticationProvider>
    {
        private List<IAuthenticationProvider> _InnerList = new List<IAuthenticationProvider>();

        public AuthenticationProviderCollection(IList<IAuthenticationProvider> providers)
        {
            foreach (IAuthenticationProvider provider in providers)
            {
                Add(provider);
            }
        }

        [Obsolete]
        public IAuthenticationProvider GetAuthenticationProvider(string credentialType, string tag)
        {
            //List<IAuthenticationProvider> list = new List<IAuthenticationProvider>();
            //foreach (var p in _InnerList)
            //{
            //    if (string.Compare(credentialType, p.CredentialType, true) == 0
            //        && CheckTag(p.Tag, tag))
            //    {
            //        return p;
            //    }
            //}
            
            return null;
        }

        private bool CheckTag(string tagOfProvider, string tagToAuthenticate)
        {
            if (string.IsNullOrEmpty(tagToAuthenticate))
            {
                return true;
            }
            return string.Compare(tagOfProvider, tagToAuthenticate, true) == 0;
        }

        internal void Add(IAuthenticationProvider provider)
        {
            _InnerList.Add(provider);
        }

        #region IEnumerable<IAuthenticationProvider> Members

        public IEnumerator<IAuthenticationProvider> GetEnumerator()
        {
            return _InnerList.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return _InnerList.GetEnumerator();
        }

        #endregion
    }
}
